From: Jonas Dreßler Date: Mon, 27 Jan 2020 17:43:40 +0000 (+0100) Subject: shellMountDialog: Check for changes before creating new buttons X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~781^2^2~112 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=0b51a52c9b683c812b96c970ff1c45cf352907eb;p=gnome-shell.git shellMountDialog: Check for changes before creating new buttons When updating the buttons of the mount dialogs, compare the new buttons to the old ones and only create new buttons in case something changed. This makes sure key focus isn't reset or lost unnecessarily while a dialog is opened. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/961 --- diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js index 72eabe34d..59a4e6e0f 100644 --- a/js/ui/shellMountOperation.js +++ b/js/ui/shellMountOperation.js @@ -20,18 +20,23 @@ var WORK_SPINNER_ICON_SIZE = 16; const REMEMBER_MOUNT_PASSWORD_KEY = 'remember-mount-password'; /* ------ Common Utils ------- */ -function _setButtonsForChoices(dialog, choices) { +function _setButtonsForChoices(dialog, oldChoices, choices) { let buttons = []; + let buttonsChanged = oldChoices.length !== choices.length; for (let idx = 0; idx < choices.length; idx++) { let button = idx; + + buttonsChanged = buttonsChanged || oldChoices[idx] !== choices[idx]; + buttons.unshift({ label: choices[idx], action: () => dialog.emit('response', button), }); } - dialog.setButtons(buttons); + if (buttonsChanged) + dialog.setButtons(buttons); } function _setLabelsForMessage(content, message) { @@ -225,13 +230,16 @@ var ShellMountQuestionDialog = GObject.registerClass({ _init() { super._init({ styleClass: 'mount-question-dialog' }); + this._oldChoices = []; + this._content = new Dialog.MessageDialogContent(); this.contentLayout.add_child(this._content); } update(message, choices) { _setLabelsForMessage(this._content, message); - _setButtonsForChoices(this, choices); + _setButtonsForChoices(this, this._oldChoices, choices); + this._oldChoices = choices; } }); @@ -463,6 +471,8 @@ var ShellProcessesDialog = GObject.registerClass({ _init() { super._init({ styleClass: 'processes-dialog' }); + this._oldChoices = []; + this._content = new Dialog.MessageDialogContent(); this.contentLayout.add_child(this._content); @@ -499,7 +509,8 @@ var ShellProcessesDialog = GObject.registerClass({ update(message, processes, choices) { this._setAppsForPids(processes); _setLabelsForMessage(this._content, message); - _setButtonsForChoices(this, choices); + _setButtonsForChoices(this, this._oldChoices, choices); + this._oldChoices = choices; } });